package com.amex.uam.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.amex.uam.dao.AmexBusDao;
import com.amex.uam.model.AMEX_BUSINESS;

@Repository("amexBusDao")
public class AmexBusDaoImpl extends JdbcDao implements AmexBusDao {

	@Override
	public boolean addBusiness(AMEX_BUSINESS bus) {
		// TODO Auto-generated method stub
		try {
			throw new Exception("DeptDaoImpl.deleteDepartment not implemented");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean deleteBusiness(String busCd) {
		// TODO Auto-generated method stub
		try {
			throw new Exception("DeptDaoImpl.deleteDepartment not implemented");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean updateBusiness(AMEX_BUSINESS bus) {
		try {
			final String sql= "select AMEX_BUS_CD, AMEX_BUS_DS_TX from AMEX_BUSINESS where AMEX_BUS_CD = ?";
			Object[] params= {bus.getAMEX_BUS_CD()};
			RowMapper<AMEX_BUSINESS> rowMapper = ParameterizedBeanPropertyRowMapper.newInstance(AMEX_BUSINESS.class);
			List<AMEX_BUSINESS> list=this.getJdbcTemplate().query(sql, params, rowMapper);
			if (list == null || list.size() == 0) {
				final String insertSql= "insert into AMEX_BUSINESS(AMEX_BUS_CD, AMEX_BUS_DS_TX) values(?, ?)";
				Object[] insertParams={bus.getAMEX_BUS_CD(), bus.getAMEX_BUS_DS_TX()};
				this.getJdbcTemplate().update(insertSql, insertParams);
			} else {
				final String updateSql= "update AMEX_BUSINESS set AMEX_BUS_DS_TX = ? where AMEX_BUS_CD = ?";
				Object[] updateParams={bus.getAMEX_BUS_DS_TX(), bus.getAMEX_BUS_CD()};
				this.getJdbcTemplate().update(updateSql, updateParams);
			}
			
			return true ;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public AMEX_BUSINESS getBusiness(String busCd) {
		// TODO Auto-generated method stub
		try {
			throw new Exception("DeptDaoImpl.deleteDepartment not implemented");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	

}
